#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int a[N], b[N];
vector<int> ch[N];
int ans[N];
int bit[N];
int lowbit(int x) { return x & -x; }
void update(int x, int d) {
  for (int i = x; i <= n; i += lowbit(i)) bit[i] += d;
}
int query(int x) {
  int sum = 0;
  for (int i = x; i > 0; i -= lowbit(i)) sum += bit[i];
  return sum;
}
void dfs(int u) {
  int x = query(n) - query(a[u]);
  update(a[u], 1);
  for (int v : ch[u]) dfs(v);
  int y = query(n) - query(a[u]);
  ans[u] = y - x;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 2, n) {
    int f;
    cin >> f;
    ch[f].push_back(i);
  }
  rep(i, 1, n) b[i] = a[i];
  sort(b + 1, b + n + 1);
  rep(i, 1, n) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
  dfs(1);
  rep(i, 1, n) cout << ans[i] << endl;
  return 0;
}